<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="My97DatePicker/WdatePicker.js"></script>
    <script>
        $(function () {
            // 加载明细列表
            $.ajax({
                url:"detailedList.do",
                type:"post",
                data:{"snowId":$("[name='id']").val()},
                dataType:"json",
                success:function (obj) {
                    // 明细列表
                    for (var i in obj){
                        $("table").append(" <tr>" +
                            "            <td><input type='checkbox' class='xz' value='"+obj[i].goodsId+"' ></td>" +
                            "            <td>"+obj[i].goodsId+"</td>" +
                            "            <td>"+obj[i].goodsName+"</td>" +
                            "            <td>"+obj[i].specification+"</td>" +
                            "            <td>"+obj[i].company+"</td>" +
                            "            <td>"+obj[i].price+"</td>" +
                            "            <td>"+obj[i].num+"</td>" +
                            "            <td class='m'>"+obj[i].totalMoney+"</td>" +
                            "            <td>操作</td>" +
                            "        </tr>")
                    }
                    changMoney();
                }
            })
        })



        function changMoney() {
            var allMoney=0;
            $(".m").each(function (){
                allMoney+=eval($(this)[0].innerText);
            })
            $("[name='sums']").val(allMoney);
        }
    </script>
</head>
<body>

    <form method="post" action="add.do">
        订单编号:<input type="text" value="${snowid}" name="id">
        订单日期:<input type="text" name="orderDate"  onclick="WdatePicker()"><br>
        客户名称:<input type="text" name="cname">
        联系人:<input type="text" name="contacts">
        联系电话:<input type="text" name="phone"><br>
        优先级:<select name="priority">
                <option  VALUE="">请选择</option>
                <option  VALUE="1">1</option>
                <option  VALUE="4">4</option>
                <option  VALUE="7">7</option>
                </select>
        送货地址:<input type="text" name="address"><br>
        制单人Id:<input type="text" name="preparerid">
        制单人:<input type="text" name="preparer">
        制单时间:<input type="text" name="preTime"><br>
        总金额：<input type="text" name="sums"><br>
        附件：<input type="file" name="file">
        备注：<textarea name="comment"></textarea>

    </form>

    <input type="button" onclick="addDetail()" value="添加明细">
    <table>
        <tr>
            <td>选择</td>
            <td>产品编号</td>
            <td>产品名称</td>
            <td>产品规格</td>
            <td>产品单位</td>
            <td>产品单价</td>
            <td>产品数量</td>
            <td >总金额</td>
            <td>操作</td>
        </tr>
    </table>

    <input type="button" value="提交" onclick="add()">
</body>
<script>
    function addDetail() {
        var id=$("[name='id']").val();
        alert(id)
        location="toaddDetail.do?id="+id;
    }

    function add(){
        var formdate=new FormData($("form")[0]);
        $.ajax({
            url:"add.do",
            data:formdate,
            type:"post",
            dataType:"json",
            processData: false,
            contentType:false,
            success:function (obj) {
                if(obj>0){
                    location="list.do";
                }
            }
        })
    }
</script>
</html>
